package com.baidu.recognition.controller;

import com.baidu.aip.speech.AipSpeech;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author liuzhiqiang
 */
@RestController
@Slf4j
@CrossOrigin
@Api(tags = {"语音识别-短语音识别标准版"})
public class ShortSpeechStandardController {

    @Autowired
    private AipSpeech aipSpeech;

    @Autowired
    @Qualifier("aipSpeechSocket")
    private AipSpeech aipSpeechSocket;


    @ApiOperation(value = "http测试标准版语音识别")
    @PostMapping("httpTest")
    public String test(MultipartFile file) throws IOException {
        JSONObject asrRes2 = aipSpeech.asr(file.getBytes(), "pcm", 16000, null);
        return asrRes2.toString();
    }

    @ApiOperation(value = "socket测试准版语音识别")
    @PostMapping("socketTest")
    public String test2(MultipartFile file) throws IOException {
        JSONObject asrRes2 = aipSpeechSocket.asr(file.getBytes(), "pcm", 16000, null);
        return asrRes2.toString();
    }


}
